package com.LeeCode;

import java.util.LinkedList;
import java.util.List;

/**
 * N 叉树的前序遍历
 */

public class Code589 {
    public static void main(String[] args) {

    }

    public List<Integer> preorder(Node root) {
        List<Integer> ans = new LinkedList<>();
        travel(root, ans);
        return ans;
    }

    private void travel(Node root, List<Integer> list) {
        if(root == null) return;
        list.add(root.val);
        for(Node node : root.children) {
            travel(node, list);
        }
    }

    class Node {
        public int val;
        public List<Node> children;

        public Node() {
        }

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }
}
